package com.ambulance.project.biz.controller.pad;

import com.ambulance.common.exception.CustomException;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.domain.AjaxResultData;
import com.ambulance.project.biz.entity.Gcs;
import com.ambulance.project.biz.service.GcsService;
import com.ambulance.utils.ChildUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = {"随车医生-GCS相关接口"})
@Controller
@RequestMapping(value = "/pad/v1/GCS", method = RequestMethod.POST)
public class GCSController {

    @Autowired
    private GcsService gcsService;

    @RequestMapping(value = "/add")
    @ResponseBody
    @ApiOperation(value = "添加GCS", notes = "添加GCS", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "value", value = "题干/答案", required = true, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "number", value = "分数", required = true, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "pid", value = "父id", required = true, paramType = "form", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    public Object add(
            @RequestParam(value = "value") String value,
            @RequestParam(value = "number") Integer number,
            @RequestParam(value = "pid", required = false, defaultValue = "0") Integer pid
    ) {
        final Gcs gcs = new Gcs();
        gcs.setValue(value);
        gcs.setNumber(number);
        gcs.setPid(pid);
        final boolean save = gcsService.save(gcs);
        return AjaxResult.AutoResponse(save);
    }

    @ApiOperation(value = "GCS列表", notes = "GCS列表", produces = "application/json")
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数不正确"),
            @ApiResponse(code = 404, message = "404请求路径不正确"),
            @ApiResponse(code = 200, response = Gcs.class, message = "响应")
    })
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list() {
        final List<Gcs> gcsList = gcsService.list();
        return AjaxResult.success(ChildUtils.getGCSChild(gcsList));
    }


    //    @RequestMapping(value = "/delete")
//    @ResponseBody
//    @ApiOperation(value = "删除GCS", notes = "删除GCS", produces = "application/json")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "GCS编号", required = true, paramType = "form", dataType = "int")
//    })
//    @ApiResponses({
//            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
//    })
    public Object delete(@RequestParam(value = "id") Integer id
    ) {
        try {
            boolean b = gcsService.removeById(id);
            return AjaxResult.AutoResponse(b);
        } catch (Exception e) {
            throw new CustomException("系统繁忙");
        }
    }

    //    @RequestMapping(value = "/update")
//    @ResponseBody
//    @ApiOperation(value = "更新GCS信息", notes = "更新GCS信息", produces = "application/json")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "GCS编号", required = true, paramType = "form", dataType = "int"),
//            @ApiImplicitParam(name = "value", value = "题干/答案", required = false, paramType = "form", dataType = "String"),
//            @ApiImplicitParam(name = "number", value = "分数", required = false, paramType = "form", dataType = "String"),
//            @ApiImplicitParam(name = "pid", value = "父级id", required = false, paramType = "form", dataType = "int"),
//    })
//    @ApiResponses({
//            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
//    })
    public Object update(
            @RequestParam(value = "id") Integer id,
            @RequestParam(value = "value", required = false) String value,
            @RequestParam(value = "number", required = false) Integer number,
            @RequestParam(value = "pid", required = false, defaultValue = "0") Integer pid
    ) {
        final Gcs gcs = new Gcs();
        gcs.setId(id);
        gcs.setValue(value);
        gcs.setNumber(number);
        gcs.setPid(pid);
        final boolean b = gcsService.updateById(gcs);
        return AjaxResult.AutoResponse(b);
    }

}
